"""
-*- coding:utf-8 -*-
__project__ = 'le-bo16'
__file_name__ = 'rickey'
__author__ = 'RickeyTing'
__time__ = '2020/10/27 19:36'
__product_name = PyCharm
# code is far away from bugs with the god animal protecting
    I love animals. They taste delicious.
              ┏┓      ┏┓
            ┏┛┻━━━┛┻┓
            ┃        ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃　永无BUG！   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""


#插入语句
# import pymysql
#
# coon = pymysql.connect(host='49.233.39.160', port=3306, user='user', passwd='leboAa!#$123', database='lebo16')
# cur = coon.cursor()
#
#
# sql = """insert into students values
# ('001', '王昭君', '女', '北京', '20', '1班', '340322199001247654'),
# ('002', '诸葛亮', '男', '上海', '18', '2班', '340322199002242354'),
# ('003', '张飞', '男', '南京', '24', '3班', '340322199003247654'),
# ('004', '白起', '男', '安徽', '22', '4班', '340322199005247654'),
# ('005', '大乔', '女', '天津', '19', '3班', '340322199004247654'),
# ('006', '孙尚香', '女', '河北', '18', '1班', '340322199006247654'),
# ('007', '百里玄策', '男', '山西', '20', '2班', '340322199007247654'),
# ('008', '小乔', '女', '河南', '15', '3班', null),
# ('009', '百里守约', '男', '湖南', '21', '1班', ''),
# ('010', '妲己', '女', '广东', '26', '2班', '340322199607247654'),
# ('011', '李白', '男', '北京', '30', '4班', '340322199005267754'),
# ('012', '孙膑', '男', '新疆', '26', '3班', '340322199000297655')
#
# """
# try:
#     cur.execute(sql)
#     coon.commit()
#     print('successfully insert')
#
# except Exception as e:
#     print('failed insert', e)
#     coon.rollback()
#
# finally:
#     cur.close()
#     coon.close()




from pymysql import *
coon = connect('49.233.39.160', 'user', 'leboAa!#$123', 'lebo16', 3306)
cs = coon.cursor()

#更新语句
count = cs.execute("update students set name='123' where name='貂蝉';") #注意单引号不能同时使用，符合pep8原则，里面是单引号，外面是双引号，再外面是三引号
print(count)
coon.commit()   #注意需要提交，不然数据没有改变更新

number = input('序号')
cs.execute("select * from students where students.studentsNo=%s;", [number])

#cs.execute("select * from students where students.studentNo='%s';" % number)
#ret1 = cs.fetchone()  # 只查看一条数据  （cs是游标）
#ret1 = cs.fetchmany(4) # 任意展示查询几条数据 ，括号里不赋予值，就默认查询一条数据，假如传的数值超过数据库值，只打印查看数据库有的数据，不会报数据下标越界错误
ret1 = cs.fetchall()    # 展示查询所有的数据
print(ret1)
'or 1 = 1 or'

coon.close()

